package com.valor.custom;

import com.valor.mapper.ResUserMapper;
import com.valor.pojo.ResUser;
import com.valor.pojo.ResUserExample;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * Description:
 * Created by valor on 2018/3/2.
 */
public class Demo {
    public static void main(String[] args){
        String resource = "mybatis-config.xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            e.printStackTrace();
        }
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        SqlSessionFactory factory = builder.build(inputStream);

        ResUserExample resUserExample = new ResUserExample();
        ResUserExample.Criteria criteria = resUserExample.createCriteria();
        criteria.andPermissionsEqualTo("2");
        criteria.andOrgCodeLike("755Q");
        SqlSession sqlSession = factory.openSession();
        ResUserMapper resUserMapper =  sqlSession.getMapper(ResUserMapper.class);
        List<ResUser> list = resUserMapper.selectByExample(resUserExample);
        for (ResUser user:list){
            System.out.println(user);
        }
    }
}
